package quick.frame.core.exception;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONPathException;
import com.elvishew.xlog.XLog;

import java.net.ConnectException;

import retrofit2.HttpException;

public class CodeMsg {
	private int code;
	private String msg;

	private static final int UNAUTHORIZED = 401;
	private static final int FORBIDDEN = 403;
	private static final int NOT_FOUND = 404;
	private static final int REQUEST_TIMEOUT = 408;
	private static final int INTERNAL_SERVER_ERROR = 500;
	private static final int BAD_GATEWAY = 502;
	private static final int SERVICE_UNAVAILABLE = 503;
	private static final int GATEWAY_TIMEOUT = 504;

	//通用异常
	public static final CodeMsg SUCCESS = new CodeMsg(0,"success");
	public static final CodeMsg UNKNOWN_ERROR = new CodeMsg(10000,"未知错误");
	public static final CodeMsg SERVER_ERROR = new CodeMsg(50010,"服务端异常");
	public static final CodeMsg INTERNET_ERROR = new CodeMsg(500,"网络错误");
	public static final CodeMsg BIND_ERROR = new CodeMsg(500101, "参数校验异常：%s");
	public static final CodeMsg UNAUTHORIZED_ERROR = new CodeMsg(UNAUTHORIZED,"请求要求身份验证");
	public static final CodeMsg FORBIDDEN_ERROR = new CodeMsg(FORBIDDEN,"服务器拒绝请求");
	public static final CodeMsg NOT_FOUND_ERROR = new CodeMsg(NOT_FOUND,"请求的网址不存在");
	public static final CodeMsg REQUEST_TIMEOUT_ERROR = new CodeMsg(REQUEST_TIMEOUT,"服务器等候请求时发生超时");;
	public static final CodeMsg BAD_GATEWAY_ERROR = new CodeMsg(BAD_GATEWAY,"服务器遇到错误，无法完成请求");;
	public static final CodeMsg SERVICE_UNAVAILABLE_ERROR = new CodeMsg(SERVICE_UNAVAILABLE,"服务不可用");;
	public static final CodeMsg GATEWAY_TIMEOUT_ERROR = new CodeMsg(GATEWAY_TIMEOUT,"网关超时");;

	//登录模块
	public static final CodeMsg SESSION_ERROR = new CodeMsg(500210, "Session不存在或者已经失效");
	public static final CodeMsg PASSWORD_EMPTY = new CodeMsg(500211, "登录密码不能为空");
	public static final CodeMsg MOBILE_EMPTY = new CodeMsg(500212, "手机号不能为空");
	public static final CodeMsg MOBILE_ERROR = new CodeMsg(500213, "手机号格式错误");
	public static final CodeMsg MOBILE_NOT_EXIST = new CodeMsg(500214, "手机号不存在");
	public static final CodeMsg PASSWORD_ERROR = new CodeMsg(500215, "密码错误");
	//蓝牙模块
	
	
	//打印机模块
	
	
	//模块
	public static final CodeMsg JSON_ERROR = new CodeMsg(500301, "解析异常");
	public static final  CodeMsg CONNECTION_ERROR = new CodeMsg(500302, "网络连接错误");

	private CodeMsg() {
		super();
	}

	private CodeMsg(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}
	public int getCode() {
		return code;
	}

	public String getMsg() {
		return msg;
	}

	public CodeMsg fillArgs(Object... args) {
		int code = this.code;
		String message = String.format(this.msg, args);
		return new CodeMsg(code, message);
	}


	@Override
	public String toString() {
		return "CodeMsg [code=" + code + ", msg=" + msg + "]";
	}

}
